package com.lanju.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lanju.dao.AuthDao;
import com.lanju.dao.UserDao;
import com.lanju.entity.User;
import com.lanju.service.AuthService;

@Service
public class AuthServiceImpl implements AuthService{

	@Autowired
	AuthDao authDao;
	
	@Autowired
	UserDao userDao;
	
	@Override
	@Transactional(value="financialmarketingTM", rollbackFor = Exception.class)
	public Map<String, Object> toAuth(Map<String, Object> map) {
		Map<String, Object> result=new HashMap<String, Object>();
		try {
			User u=userDao.getByPhone(map.get("phone").toString());
			if(u!=null){
				u.setIdCard(map.get("idCard").toString());
				u.setRealName(map.get("name").toString());
				u.setSex(Integer.valueOf(map.get("sex").toString()));
				u.setJobName(map.get("jobName").toString());
				userDao.merge(u);
				result.put("success", true);
				return result;
			}
		} catch (NumberFormatException e) {
			result.put("success", false);
			e.printStackTrace();
			return result;
		}
		return result;
	}

}
